
package com.googlecode.oskis.library.db;
import java.sql.*;

/**
 * Klasse zum Zugriff auf embedded JavaDB (Derby) Datenbanken
 * @author thomas
 */
public class DerbyLocalConnection extends DBConnection {
        
    /**
     * 
     * @return
     */
    protected Connection createConnection() {
        Connection c;
        if (database==null) {
            return(null);
        }
        try {
            String applicationWorkingDirectory=System.getProperty("user.dir");
            System.setProperty("derby.system.home", applicationWorkingDirectory); 
            String dbURL="jdbc:derby:"+database;            
            c = DriverManager.getConnection(dbURL);
            connected=true;
        } catch (Exception e) {
            System.err.println(e);
            c=null;
            connected=false;
            connectionError=e.toString();
        }
        return(c);
    }
    
    
    /** Creates a new instance of PGConnection */
    public DerbyLocalConnection() {
        readProperties();
        this.db=createConnection();
    }
    public DerbyLocalConnection(String database) {
        readProperties();
        setDatabase(database);
        this.db=createConnection();
    }
    public DerbyLocalConnection(String ip,String database,String user,String passwd) {
        setDatabase(database);
        setIP(ip);
        setUser(user);
        setPasswd(passwd);
        this.db=createConnection();
    }
}
